package com.ruoyi.industry.controller.pc;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.industry.domain.ProjectBuilding;
import com.ruoyi.industry.service.IProjectBuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 楼宇办公Controller
 *
 * @author MagicCube
 * @date 2023-05-31
 */
@RestController
@RequestMapping("/frontend/building")
public class PCProjectBuildingController extends BaseController
{
    @Autowired
    private IProjectBuildingService projectBuildingService;

    /**
     * 查询楼宇办公列表
     */
    @RequiresPermissions("myIndustry:building:list")
    @GetMapping("/list")
    public TableDataInfo list(ProjectBuilding projectBuilding)
    {
        startPage();
        projectBuilding.setSupplyUserId(SecurityUtils.getUserId());
        List<ProjectBuilding> list = projectBuildingService.selectProjectBuildingListz(projectBuilding);
        return getDataTable(list);
    }

    /**
     * 导出楼宇办公列表
     */
    @RequiresPermissions("myIndustry:building:export")
    @Log(title = "楼宇办公", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectBuilding projectBuilding)
    {
        projectBuilding.setSupplyUserId(SecurityUtils.getUserId());
        List<ProjectBuilding> list = projectBuildingService.selectProjectBuildingList(projectBuilding);
        ExcelUtil<ProjectBuilding> util = new ExcelUtil<ProjectBuilding>(ProjectBuilding.class);
        util.exportExcel(response, list, "楼宇办公数据");
    }

    /**
     * 获取楼宇办公详细信息
     */
    @RequiresPermissions("myIndustry:building:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(projectBuildingService.selectProjectBuildingById(id));
    }

    /**
     * 新增楼宇办公
     */
    @RequiresPermissions("myIndustry:building:add")
    @Log(title = "楼宇办公", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectBuilding projectBuilding)
    {
        projectBuilding.setApprovalState(0L);
        return toAjax(projectBuildingService.insertProjectBuilding(projectBuilding));
    }

    /**
     * 修改楼宇办公
     */
    @RequiresPermissions("myIndustry:building:edit")
    @Log(title = "楼宇办公", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectBuilding projectBuilding)
    {
        projectBuilding.setApprovalState(0L);
        return toAjax(projectBuildingService.updateProjectBuilding(projectBuilding));
    }

    /**
     * 删除楼宇办公
     */
    @RequiresPermissions("myIndustry:building:remove")
    @Log(title = "楼宇办公", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectBuildingService.deleteProjectBuildingByIds(ids));
    }
}
